﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKRevitWndr.InsertDoorAndWindow.InsertOperation;
using YJKRevitBase.WinForm;
using YJKRevitView;

namespace YJKRevitWndr.InsertDoorAndWindow.Cmd
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdInsertDoor : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elems)
		{
			if (CmdInsertDoor._hWndRevit == null)
			{
				CmdInsertDoor._hWndRevit = new WindowHandle(Process.GetCurrentProcess().MainWindowHandle);
			}
			HideWarningKit1 @object = new HideWarningKit1(new List<string>
			{
				"ModifySymbol",
				"门",
				"StartModifyInstance"
			});
			cmdData.Application.Application.FailuresProcessing += @object.OnFailuresProcessing;
			CmdViewType types = CmdViewType.FloorPlan;
			if (SwitchView.SetUsableView(types, cmdData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			try
			{
				if (!new InsertDoorAndWindowManage(cmdData, BuiltInCategory.OST_Doors).InsertMain(CmdInsertDoor.m_strFamilyName, CmdInsertDoor.m_strFamilyType))
				{
					return Autodesk.Revit.UI.Result.Failed;
				}
			}
			catch (Exception)
			{
			}
			cmdData.Application.Application.FailuresProcessing -= @object.OnFailuresProcessing;
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public static WindowHandle _hWndRevit;

		public static string m_strFamilyName;

		public static string m_strFamilyType;
	}
}
